<template>
	<div class="content">
		
		
		<div >
			<button @click="Autolink()" style="width: 200px; margin: 10px ;">自动链接</button>
		</div>
		<span>请输入你的server url</span>
		<div class="contentinput">
			<el-input
		style="width: 40%;margin-top: 10px;"
		  placeholder="ip地址"
		  v-model="inputvalue"
		  clearable>
		</el-input>
		:
		<el-input
		style="width: 20%;margin-top: 10px;"
		  placeholder="端口"
		  v-model="port"
		  
		  clearable>
		</el-input>
			<button @click="setinputtIP()">确定</button>
			<!-- <button @click="Twoput()">确定2</button> -->
		</div>
		<el-input
		style="width: 50%;margin-top: 10px;"
		  placeholder="物体地址前缀"
		  v-model="Addressprefix"
		  @change="clickprefix()"
		  clearable>
		</el-input>
		
		
	</div>
  
    
	
  
  
</template>
<script>
    // const utils =require('../../utils.js');
    export default {
        data() {
            return {
                ip: '',
                inputvalue: this.$store.state.TextIp,
                port: this.$store.state.port,
                Addressprefix: this.$store.state.Addressprefix,
                diz: '',
                textMap: '',
            };
        },
        computed: {

        },

        mounted() {
            // this.getActor()



        },
        methods: {
            clickprefix() {
                this.$store.commit("setAddressprefix", this.Addressprefix)
                this.UpMaps()

            },



            setinputtIP() {


                let demo = "http://" + this.inputvalue + ":" + this.port
                this.diz = demo

                this.$store.commit("setuserinputIP", demo) //api接口的地址
                    // alert(demo)

                // this.axios.get("http://192.168.10.160:30010/remote/presets").then((res)=>{
                // 	alert('成功')

                // 	console.log(res)
                // }).watch((err)=>{
                // 	alert("失败")
                // 	console.log(err)
                // if(this.inputvalue != ''){

                // 	this.Autolink()
                // }else{
                // 	alert("链接失败")
                // }

                // }) 


                if (demo.length >= 20) {
                    this.axios.get(demo + "/remote/presets").then(
                        (res) => {
                            this.$store.commit('setipTips', true)

                            this.$store.commit("setTextIp", this.inputvalue) //ip
                            this.$store.commit("setport", this.port) //端口号
                            this.$store.commit("setuserinputIP", demo) //api接口的地址
                            this.getActor()
                            console.log("111111111")


                        }, // 成功

                        (err) => {
                            this.$store.commit('setipTips', false)
                            alert("链接失败2")
                        } // 失败
                    )
                } else {
                    alert("链接失败1")
                    this.$store.commit('setipTips', false)
                }

                // utils.sendThis(this);




            },
            Autolink() {
                this.axios({　　
                    method: 'get',
                    　　url: '/remote/presets',
                    　
                }).then((res) => {

                        this.$store.commit("setTextIp", 'localhost') //ip
                        this.getActor()
                        this.$store.commit('setipTips', true)
                            // console.log(this.$store.state.userinputIP)
                        console.log("111111111")
                    },
                    (err) => {

                        this.$store.commit('setipTips', false)
                            // console.log(this.$store.state.userinputIP)
                        alert("链接失败1")
                    }

                )
            },




            getActor() {

                // let demo="http"+"://" +this.inputvalue+':'+this.port
                this.axios.put('/remote/object/call', {
                    "objectPath": "/Script/EditorScriptingUtilities.Default__EditorLevelLibrary",
                    "functionName": "GetAllLevelActors"
                }, {
                    headers: {
                        'Content-Type': 'application/json'
                    }
                }).then(
                    (res) => {

                        console.log("链接成功")
                        this.$store.commit('serObjectPath', res.data) //更新ObjectPath
                        let test = res.data.ReturnValue[1]
                        this.UpMaps()

                        if (this.textMap != '') {
                            let textMaptrue = true
                            this.$store.commit('setaddproperties', textMaptrue) //识别是那种类型temp还是game

                        }


                    },
                    (err) => {
                        console.log("获取地图物体路径失败")
                    }

                )
            },
            Twoput() {
                this.axios.put('/object/call', {
                    "objectPath": "/Script/EditorScriptingUtilities.Default__EditorLevelLibrary",
                    "functionName": "GetAllLevelActors"
                }, {
                    headers: {
                        'Content-Type': 'application/json'
                    }
                }).then(
                    (res) => {
                        console.log(res)
                    },
                    (err) => {
                        console.log("shibai?2")
                    }
                )
            }


        }
    }
</script>

<style scoped="scoped">
    .content span {
        width: 100%;
        color: #F0F8FF;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    
    .content button {
        height: 40px;
        border-radius: 10px;
        background-color: #FFF;
        margin-left: 10px;
        width: 20%;
    }
    
    .contentinput {
        color: #FFFFFF;
    }
    
    .jskj {
        width: 30px;
        height: 30px;
        background-color: aqua;
    }
</style>